package Tools;

import java.io.*;

/**
 * @Author: 0162977
 * @Date: 2020/11/12 15:01
 */
public class FileTools {

    public static void FileOutPut(String FilePath, int[][] arr) throws IOException {

        File file = new File(FilePath);  //存放数组数据的文件

        FileWriter out = new FileWriter(file);  //文件写入流

        //将数组中的数据写入到文件中。每行各数据之间TAB间隔
        for(int i=0;i<arr.length;i++){
            for(int j=0;j<arr[0].length;j++){
                out.write(arr[i][j]+"\t");
            }
            out.write("\r\n");
        }
        out.close();
    }

    public static  int[][] FileInPut(String FilePath) throws IOException {

        int[][] arr2 = new int[16][16];;  //读取出的数组
        BufferedReader in = new BufferedReader(new FileReader(FilePath));  //
        String line;  //一行数据
        int row=0;
        //逐行读取，并将每个数组放入到数组中
        while((line = in.readLine()) != null){
            String[] temp = line.split("\t");
            for(int j=0;j<temp.length;j++){
                arr2[row][j] = Integer.parseInt(temp[j]);
            }
            row++;
        }
        in.close();

        return arr2;

    }

}
